package lumis.portal.presentation.perspective.admin;

import java.io.Serializable;

import lumis.portal.presentation.perspective.IPortalMode;

import org.apache.wicket.MarkupContainer;
import org.apache.wicket.markup.IMarkupResourceStreamProvider;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.PackageResourceStream;

/**
 * Markup resource stream provider used when inside the Portal Studio.
 * Generates {@link PortalStudioMarkupResourceStream} instances.
 *
 * @version $Revision: 13093 $ $Date: 2011-05-28 18:40:18 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
@SuppressWarnings("serial")
public class PortalStudioMarkupResourceStreamProvider implements IMarkupResourceStreamProvider, Serializable 
{
	/**
	 * The markup resource stream provider to be used as base, or
	 * <code>null</code> if a safe mode markup is to be used.
	 * @since 6.0.0
	 */
	private final IMarkupResourceStreamProvider markupResourceStreamProvider;

	/**
	 * The current portalMode.
	 */
	private final IPortalMode portalMode;

	/**
	 * The file name.
	 */
	private final String fileName;
	
	/**
	 * Creates a new markup resource stream provider for Portal Studio,
	 * using the given file.
	 * @since 6.0.0
	 */
	public PortalStudioMarkupResourceStreamProvider(String filename,IPortalMode portalMode)
	{
		this.fileName = filename;
		this.portalMode = portalMode;
		this.markupResourceStreamProvider = null;
		
		
	}
	
	/**
	 * Creates a new markup resource stream provider for Portal Studio,
	 * based on the given markup provider.
	 * @since 6.0.0
	 */
	public PortalStudioMarkupResourceStreamProvider(IMarkupResourceStreamProvider markupResourceStreamProvider, IPortalMode portalMode)
	{
		this.markupResourceStreamProvider = markupResourceStreamProvider;
		this.portalMode = portalMode;
		this.fileName = null;
	}

	public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass)
	{
		IResourceStream baseResourceStream;
		if (markupResourceStreamProvider != null)
			baseResourceStream = markupResourceStreamProvider.getMarkupResourceStream(container, containerClass);
		else
			baseResourceStream = new PackageResourceStream(PortalStudioMarkupResourceStreamProvider.class, fileName);
		
		return new PortalStudioMarkupResourceStream(baseResourceStream, container, portalMode);
	}
}
